package com.pti.usermanager.web.controller;

import com.pti.usermanager.dao.po.OrgPo;
import com.pti.usermanager.dao.po.PostPo;
import com.pti.usermanager.service.api.PostService;
import com.pti.usermanager.web.dto.request.*;
import com.pti.usermanager.web.dto.request.SavePostRequest;
import com.pti.usermanager.web.dto.request.UpdatePostRequest;
import com.pti.usermanager.web.dto.response.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: PostController
 * @Author: dongzhipeng
 * @Description: 岗位控制层
 * @Date: 2019/1/17
 */
@RestController
@Api(value = "岗位管理接口",tags="提供岗位的管理接口")
public class PostController {

    private static final Logger logger = LogManager.getLogger(PostController.class);

    @Autowired
    private PostService postService;

    @GetMapping("/post/getPostTree/{usrId}/{orgId}")
    @ApiOperation(value = "获取岗位树结构" , notes = "获取岗位树结构",produces = "application/json")
    public ResultResponse getPostTree(@PathVariable(value = "usrId") Long usrId,@PathVariable(value = "orgId") Long orgId){
        logger.debug("usrId:{}",usrId);
        logger.debug("orgId:{}",orgId);

        return postService.findPostByDeptId(usrId,orgId);
    }

    @PostMapping("/post/savePost")
    @ApiOperation(value = "添加岗位列表" , notes = "添加岗位列表",produces = "application/json")
    public ResultResponse savePost(@RequestBody SavePostRequest savePostRequest){
        return postService.savePost(savePostRequest);
    }

    @PutMapping("/post/updatePost")
    @ApiOperation(value = "修改岗位列表" , notes = "修改岗位列表",produces = "application/json")
    public ResultResponse updatePost(@RequestBody UpdatePostRequest updatePostRequest){
        return postService.updatePost(updatePostRequest);
    }

    @DeleteMapping("/post/delPost/{postId}")
    @ApiOperation(value = "删除岗位" , notes = "删除岗位",produces = "application/json")
    public ResultResponse delPost(@PathVariable(value = "postId") Long postId){
        logger.debug("postId:{}",postId);
        return postService.delPost(postId);
    }

    @PostMapping("/post/assignUser")
    @ApiOperation(value = "分配用户",notes = "分配用户",produces = "application/json")
    public ResultResponse assignUser(@RequestBody  SaveUserByPidAndUid saveUserByPidAndUid){
        return postService.saveUserByPidAndUid(saveUserByPidAndUid);
    }

    @GetMapping("/post/postDetail/{postId}")
    @ApiOperation(value = "岗位详情",notes = "岗位详情",produces = "application/json")
    public ResultResponse findAllByPostId(@PathVariable("postId") Long postId){
        return postService.findAllByPostId(postId);
    }
}
